﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LotteryLastTermPanel : MonoBehaviour
{
    public Text m_TitleL;
    public Text m_HitNumberL;
    public GameObject m_LastTermBoughtNumberList;
    public LastTermNumberItem m_LastTermItemPerfab;
    public List<LastTermNumberItem> m_LastTermItems = new List<LastTermNumberItem>();

    public AudioSource m_PrizeSound1;
    public AudioSource m_PrizeSound2;
    public AudioSource m_PrizeSound3;
    public AudioSource m_PrizeSound4;
    void Start()
    {
        int lastTermSeed = UtilsGame.GetSeedToday() - 1;
        m_TitleL.text = "第 " + lastTermSeed + " 期地联福利彩票";

        int hitNumber = (int)(((UtilsMath.rand(lastTermSeed, 123456) +1f)*0.5f) * 1000f);
        m_HitNumberL.text = hitNumber.ToString().PadLeft(4, '0');

        for(int i=0; i< Player.Instance.m_LotteryLastTerm.Count; ++i)
        {
            var item = Instantiate(m_LastTermItemPerfab);
            item.transform.SetParent(m_LastTermBoughtNumberList.transform);
            item.transform.localScale = new Vector3(1,1,1);
            item.CallbackOnRecivePrize = OnRecivePrize;
            item.Init(Player.Instance.m_LotteryLastTerm[i], hitNumber);
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void OnRecivePrize(int hitNumber, int selfNumber)
    {
        int getMoney = 0;
        switch (hitNumber)
        {
            case 4:
                getMoney = 500000;
                m_PrizeSound2.Play();
                m_PrizeSound4.Play();
                break;
            case 3:
                getMoney = 40000;
                m_PrizeSound2.Play();
                m_PrizeSound3.Play();
                break;
            case 2:
                getMoney = 3000;
                m_PrizeSound1.Play();
                m_PrizeSound2.Play();
                break;
            case 1:
                getMoney = 200;
                m_PrizeSound1.Play();
                break;
        }
        Player.Instance.Money += getMoney;
        Player.Instance.m_LotteryLastTerm.Remove(selfNumber);
        Player.Instance.save();
        MessageShow.Instance.Messaage("你得到了 "+getMoney+" 块钱的奖金！！！");
    }
}
